package org.oslims.client.view.impl;

import org.oslims.client.uicomponents.editbox.EditDepartmentBox;
import org.oslims.client.view.DepartmentEditorView;
import org.oslims.domain.Department;

import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.SimplePager;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DockLayoutPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

public class DepartmentEditorViewImpl extends BaseViewImpl implements DepartmentEditorView {

	Integer defaultPageSize = 15;

	private CellTable<Department> departmentTable = new CellTable<Department>();
	private SimplePager<Department> pager = new SimplePager<Department>(departmentTable);

	private Button newDepartmentButton = new Button("New Department");
	private EditDepartmentBox editDepartmentBox = new EditDepartmentBox();

	public DepartmentEditorViewImpl() {

		DockLayoutPanel content = new DockLayoutPanel(Unit.PCT);
		content.setStyleName("mainContent");

		VerticalPanel headerPanel = new VerticalPanel();

		Label header = new Label("Department Management");
		headerPanel.add(header);
		content.addNorth(headerPanel, 5);

		VerticalPanel footerPanel = new VerticalPanel();
		footerPanel.add(pager);
		footerPanel.add(newDepartmentButton);
		content.addSouth(footerPanel, 10);

		ScrollPanel tablePanel = new ScrollPanel();
		tablePanel.add(departmentTable);

		content.add(tablePanel);

		initWidget(content);
	}

	public CellTable<Department> getTable() {
		return departmentTable;
	}

	public HasClickHandlers getNewDepartmentButton() {
		return newDepartmentButton;
	}

	@Override
	public EditDepartmentBox getEditDepartmentBox() {
		return editDepartmentBox;
	}

	@Override
	public Integer getDefaultPageSize() {
		return defaultPageSize;
	}

	@Override
	public SimplePager<Department> getPager() {
		return pager;
	}

}
